//获取api-url 层
import api_url from './api-url.js'
import request from './request.js'
// 正式版

// const API_BASE = 'https://smallapp-api.wowdsgn.com/';
// 测试版 121
// const API_BASE = 'http://smallapp-api.intra.wowdsgn.com/';
const API_BASE = 'http://small-app.natapp1.cc/';
/**
 * 获取请求时URL
 * @returns {string}
 */
function getRequestURL(url) {
  return API_BASE + url;
}
// 请求网络产品组
function getGoodsGroupList(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_GroupList), params, 'application/json', successCallback, errorCallback, completeCallback);
}
// 登录
function login(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_Login), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}

// 首页列表
function get_productData(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Index_ProductData), params, 'application/json', successCallback, errorCallback, completeCallback);
}

// 首页banner列表
function get_bannerData(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Index_BannerData), params, 'application/json', successCallback, successCallback, completeCallback);
}

// 添加收货地址
function post_addAddress(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_AddressAdd), params, 'application/json', successCallback, errorCallback, completeCallback);
}
// 获取收货地址列表
function get_addressList(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_AddressAdd), params, 'application/json', successCallback, errorCallback, completeCallback);
}
// 删除收货地址
function delete_address(params, successCallback, errorCallback, completeCallback) {
  request.delete(getRequestURL(api_url.API_AddressAdd) + '/' + params, {}, 'application/json', successCallback, errorCallback, completeCallback);
}
// 修改收货地址
function put_changenAddress(params, successCallback, errorCallback, completeCallback) {
  request.put(getRequestURL(api_url.API_AddressAdd), params, 'application/json', successCallback, errorCallback, completeCallback);
}
// 设置当前地址为默认地址
function put_setDefaultAddress(params, successCallback, errorCallback, completeCallback) {
  request.put(getRequestURL(api_url.API_AddressAdd) + '/' + params + '/default', {}, 'application/json', successCallback, errorCallback, completeCallback);
}
// 获取产品详情数据
function get_productDetails(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Product_Details) + '/' + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取产品规格
function get_productStandard(params, successCallback, errorCallback, completeCallback) {
  request.get(API_BASE + 'v1/itemdetail/spec/toAddCart/' + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 添加商品到购物车
function post_addToCart(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_AddTo_Cart), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 领优惠券
function post_coupons(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_Coupons), params, 'application/json', successCallback, errorCallback, completeCallback)
}

//我的优惠券列表
function get_coupons(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Coupons), params, 'application/json', successCallback, errorCallback, completeCallback)
}

//可领优惠券列表
function get_recommendCoupons(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Recommend_Coupons), 'application/json', params, successCallback, errorCallback, completeCallback)
}

//可领优惠券列表
function get_useableCoupons(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Useable_Coupons), 'application/json', params, successCallback, errorCallback, completeCallback)
}


// 查询购物车列表
function get_cart(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Cart), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 删除购物车中产品
function delete_cart(params, successCallback, errorCallback, completeCallback) {
  request.delete(getRequestURL(api_url.API_V1_Cart), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 修改购物车中产品数量
function put_cart(params, successCallback, errorCallback, completeCallback) {
  request.put(getRequestURL(api_url.API_V1_Cart), params, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取订单详情
function get_orderDetail(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Orders) + '/' + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 取消订单
function delete_order(params, successCallback, errorCallback, completeCallback) {
  request.delete(getRequestURL(api_url.API_Orders) + '/' + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 用户确定收货
function put_order(params, successCallback, errorCallback, completeCallback) {
  request.put(getRequestURL(api_url.API_Orders) + '/' + params + '/status', {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 将购物车中的产品设置为已选中(未选中)
function put_cartSelected(params, successCallback, errorCallback, completeCallback) {
  request.put(getRequestURL(api_url.API_Cart_Selected), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取专题相关信息
function get_topic(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Topic) + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取专题相关信息
function get_topicProduct(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Topic_Products) + params.groupId + '/products?pageSize=' + params.pageSize + '&currentPage=' + params.currentPage, {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 查询订单列表
function getOrders(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Orders), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 创建订单
function createOrder(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_API_V2_Orders), params, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取支付凭证
function getCharge(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Charge), params, 'application/json', successCallback, errorCallback, completeCallback)
}
// 查询支付结果
function getPayResult(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_PayResult) + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取购物车中选择的产品的结算信息
function settle(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Settle), {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取默认收货地址
function getDefaultAddress(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_AddressDefault), {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取商品评论列表
function getProductComments(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_ProductCOMMENTS) + "?skuId=" + params + "&pageSize=3&currentPage=1", {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取相关商品
function getRelatedProducts(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_RelatedProducts) + params + "/recommendation", {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取活动商品列表
function getPromotionProducts(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Promotion_products), params, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取品牌商品列表
function getBrandProducts(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Brand_product) + params.brandId + '/items?pageSize=' + params.pageSize + '&currentPage=' + params.currentPage, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取品牌详情
function getBrandDetail(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Brand_detail) + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取设计师商品列表

function getDesignerProducts(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Designer_product) + params.designerId + '/items?pageSize=' + params.pageSize + '&currentPage=' + params.currentPage, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取设计师详情
function getDesignerDetail(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Designer_detail) + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取搜索热词
function getHotWords(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Search_hot_words), {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取搜索结果
function getSearchResult(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Search_product + "?" + "pageSize=" + params.pageSize + '&currentPage=' + params.currentPage + "&keyword=" + params.keyword + "&sort=" + params.sort + "&order=" + params.order), {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 详情页基本信息
function getDetailBaseInfo(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Detail_BaseInfo + params), {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// 获取详情页sku活动信息
function getDetailSkuInfos(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_Detail_SkuInfo + params), {}, 'application/json', successCallback, errorCallback, completeCallback)

}
// 获取详情页规格弹窗
function getDetailSpecific(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_Detail_SpecificInfo + params), {}, 'application/json', successCallback, errorCallback, completeCallback)

}

// 激活用户绑定的礼品卡
function activateGiftCard(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_GiftCard_activate), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}

// 获取礼品卡专题页下的商品 
function getGiftCardProduct(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_GiftCard_product), {}, 'application/json', successCallback, errorCallback, completeCallback)
}


// 获取礼品卡使用记录
function getGiftCardUselog(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_GiftCard_uselog), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)

}

//获取用户激活的有余额的礼品卡
function getGiftCardWithbalance(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_GiftCard_withbalance), params, 'application/json', successCallback, errorCallback, completeCallback)

}

//获取用户激活的已用完的礼品卡
function getGiftCardWithoutbalance(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_GiftCard_withoutbalance), params, 'application/json', successCallback, errorCallback, completeCallback)

}

// 获取用户当前可用的全部礼品卡
function getGiftCardAvailable(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_GiftCard_available), {}, 'application/json', successCallback, errorCallback, completeCallback)
}

//立即购买结算

function getSettleBuyNow(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_Settle_BuyNow), params, 'application/json', successCallback, errorCallback, completeCallback)

}
//资源配置
function getResources(params, successCallback, errorCallback, completeCallback) {
  return request.get(getRequestURL(api_url.API_Resources), params, 'application/json', successCallback, errorCallback, completeCallback)

}
//发送手机登录请求验证码
function post_sendLoginCaptcha(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_sendLoginCaptcha), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//手机验证码登录/注册
function post_loginByCaptcha(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_loginByCaptcha), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//绑定手机
function post_bindMobile(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_bindMobile), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//绑定微信
function post_bindWechat(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_bindWechat), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//用户退出登录
function post_logout(successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_logout), {}, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//校验是否需要手机号
function post_checkMobileAuth(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_checkMobileAuth), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//用户信息
function get_userInfo(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_userInfo), {}, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
//首页数据
function get_index(successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_index), {}, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}
// 领取优惠券数据
function post_coupon(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_coupons), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}

// 获取产品组相关信息
function get_group(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_productGroup) + params, {}, 'application/json', successCallback, errorCallback, completeCallback)
}

// 获取产品组相关产品
function get_groupProduct(params, successCallback, errorCallback, completeCallback) {
  request.get(getRequestURL(api_url.API_productGroup) + params.groupId + '/products?pageSize=' + params.pageSize + '&currentPage=' + params.currentPage, {}, 'application/json', successCallback, errorCallback, completeCallback)
}
// code换session
function post_code2Session(params, successCallback, errorCallback, completeCallback) {
  request.post(getRequestURL(api_url.API_code2SessionL), params, 'application/x-www-form-urlencoded', successCallback, errorCallback, completeCallback)
}

module.exports = {
  getGoodsGroupList: getGoodsGroupList,
  get_addressList: get_addressList,
  get_productData: get_productData,
  get_bannerData: get_bannerData,
  get_productDetails: get_productDetails,
  get_productStandard: get_productStandard,
  get_recommendCoupons: get_recommendCoupons,
  get_coupons: get_coupons,
  get_orderDetail: get_orderDetail,
  getPayResult: getPayResult,
  post_addToCart: post_addToCart,
  post_coupons: post_coupons,
  post_addAddress: post_addAddress,
  delete_address: delete_address,
  delete_order: delete_order,
  delete_cart: delete_cart,
  put_cart: put_cart,
  put_cartSelected: put_cartSelected,
  put_changenAddress: put_changenAddress,
  put_setDefaultAddress: put_setDefaultAddress,
  put_order: put_order,
  login: login,
  get_cart: get_cart,
  get_topic: get_topic,
  get_topicProduct: get_topicProduct,
  getOrders: getOrders,
  getCharge: getCharge,
  settle: settle,
  getDefaultAddress: getDefaultAddress,
  get_useableCoupons: get_useableCoupons,
  createOrder: createOrder,
  getProductComments: getProductComments,
  getRelatedProducts: getRelatedProducts,
  getPromotionProducts: getPromotionProducts,
  getBrandProducts: getBrandProducts,
  getBrandDetail: getBrandDetail,
  getDesignerProducts: getDesignerProducts,
  getDesignerDetail: getDesignerDetail,
  getHotWords: getHotWords,
  getSearchResult: getSearchResult,
  getDetailBaseInfo: getDetailBaseInfo,
  getDetailSkuInfos: getDetailSkuInfos,
  getDetailSpecific: getDetailSpecific,
  activateGiftCard: activateGiftCard,
  getGiftCardProduct: getGiftCardProduct,
  getGiftCardUselog: getGiftCardUselog,
  getGiftCardWithbalance: getGiftCardWithbalance,
  getGiftCardWithoutbalance: getGiftCardWithoutbalance,
  getGiftCardAvailable: getGiftCardAvailable,
  getSettleBuyNow: getSettleBuyNow,
  getResources: getResources,
  post_sendLoginCaptcha: post_sendLoginCaptcha,
  post_loginByCaptcha: post_loginByCaptcha,
  post_logout: post_logout,
  post_checkMobileAuth: post_checkMobileAuth,
  get_userInfo: get_userInfo,
  get_index: get_index,
  post_coupon: post_coupon,
  post_bindWechat: post_bindWechat,
  post_bindMobile: post_bindMobile,
  get_group: get_group,
  get_groupProduct: get_groupProduct,
  post_code2Session: post_code2Session

};